home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / timidsrc.zip / output.c < prev    next >
C/C++ Source or Header  |  1997-02-11  |  4KB  |  179 lines

  1. /* 
  2.  
  3.     TiMidity -- Experimental MIDI to WAVE converter
  4.     Copyright (C) 1995 Tuukka Toivonen <toivonen@clinet.fi>
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 2 of the License, or
  9.     (at your option) any later version.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.     output.c
  21.     
  22.     Audio output (to file / device) functions.
  23. */
  24.  
  25. #include "config.h"
  26. #include "output.h"
  27. #include "tables.h"
  28.  
  29.  
  30. /* These are very likely mutually exclusive.. */
  31. #ifdef AU_DEC
  32. extern PlayMode dec_play_mode;
  33. #define DEFAULT_PLAY_MODE &dec_play_mode
  34. #endif
  35.  
  36. #ifdef AU_LINUX
  37. extern PlayMode linux_play_mode;
  38. #define DEFAULT_PLAY_MODE &linux_play_mode
  39. #endif
  40.  
  41. #ifdef AU_HPUX
  42. extern PlayMode hpux_play_mode;
  43. #define DEFAULT_PLAY_MODE &hpux_play_mode
  44. #endif
  45.  
  46. #ifdef AU_SUN
  47. extern PlayMode sun_play_mode;
  48. #define DEFAULT_PLAY_MODE &sun_play_mode
  49. #endif
  50.  
  51. #ifdef AU_WIN32
  52. extern PlayMode win32_play_mode;
  53. #define DEFAULT_PLAY_MODE &win32_play_mode
  54. #endif
  55.  
  56. #ifdef AU_DART
  57. extern PlayMode dart_play_mode;
  58. #define DEFAULT_PLAY_MODE &dart_play_mode
  59. #endif
  60.  
  61. #ifdef AU_RTMMM
  62. extern PlayMode rtmmm_play_mode;
  63. #endif
  64.  
  65. /* These are always compiled in. */
  66. extern PlayMode raw_play_mode, wave_play_mode;
  67.  
  68. PlayMode *play_mode_list[] = {
  69. #ifdef DEFAULT_PLAY_MODE
  70.   DEFAULT_PLAY_MODE,
  71. #endif
  72. #ifdef AU_RTMMM
  73.   &rtmmm_play_mode,
  74. #endif  
  75.   &wave_play_mode,
  76.   &raw_play_mode,
  77.   0
  78. };
  79.  
  80. #ifdef DEFAULT_PLAY_MODE
  81.   PlayMode *play_mode=DEFAULT_PLAY_MODE;
  82. #else
  83.   PlayMode *play_mode=&wave_play_mode;
  84. #endif
  85.  
  86. /*****************************************************************/
  87. /* Some functions to convert signed 32-bit data to other formats */
  88.  
  89. void s32tos8(int32 *lp, int32 c)
  90. {
  91.   int8 *cp=(int8 *)(lp);
  92.   int32 l;
  93.   while (c--)
  94.     {
  95.       l=(*lp++)>>(32-8-GUARD_BITS);
  96.       if (l>127) l=127;
  97.       else if (l<-128) l=-128;
  98.       *cp++ = (int8) (l);
  99.     }
  100. }
  101.  
  102. void s32tou8(int32 *lp, int32 c)
  103. {
  104.   uint8 *cp=(uint8 *)(lp);
  105.   int32 l;
  106.   while (c--)
  107.     {
  108.       l=(*lp++)>>(32-8-GUARD_BITS);
  109.       if (l>127) l=127;
  110.       else if (l<-128) l=-128;
  111.       *cp++ = 0x80 ^ ((uint8) l);
  112.     }
  113. }
  114.  
  115. void s32tos16(int32 *lp, int32 c)
  116. {
  117.   int16 *sp=(int16 *)(lp);
  118.   int32 l;
  119.   while (c--)
  120.     {
  121.       l=(*lp++)>>(32-16-GUARD_BITS);
  122.       if (l > 32767) l=32767;
  123.       else if (l<-32768) l=-32768;
  124.       *sp++ = (int16)(l);
  125.     }
  126. }
  127.  
  128. void s32tou16(int32 *lp, int32 c)
  129. {
  130.   uint16 *sp=(uint16 *)(lp);
  131.   int32 l;
  132.   while (c--)
  133.     {
  134.       l=(*lp++)>>(32-16-GUARD_BITS);
  135.       if (l > 32767) l=32767;
  136.       else if (l<-32768) l=-32768;
  137.       *sp++ = 0x8000 ^ (uint16)(l);
  138.     }
  139. }
  140.  
  141. void s32tos16x(int32 *lp, int32 c)
  142. {
  143.   int16 *sp=(int16 *)(lp);
  144.   int32 l;
  145.   while (c--)
  146.     {
  147.       l=(*lp++)>>(32-16-GUARD_BITS);
  148.       if (l > 32767) l=32767;
  149.       else if (l<-32768) l=-32768;
  150.       *sp++ = XCHG_SHORT((int16)(l));
  151.     }
  152. }
  153.  
  154. void s32tou16x(int32 *lp, int32 c)
  155. {
  156.   uint16 *sp=(uint16 *)(lp);
  157.   int32 l;
  158.   while (c--)
  159.     {
  160.       l=(*lp++)>>(32-16-GUARD_BITS);
  161.       if (l > 32767) l=32767;
  162.       else if (l<-32768) l=-32768;
  163.       *sp++ = XCHG_SHORT(0x8000 ^ (uint16)(l));
  164.     }
  165. }
  166.  
  167. void s32toulaw(int32 *lp, int32 c)
  168. {
  169.   uint8 *up=(uint8 *)(lp);
  170.   int32 l;
  171.   while (c--)
  172.     {
  173.       l=(*lp++)>>(32-13-GUARD_BITS);
  174.       if (l > 4095) l=4095;
  175.       else if (l<-4096) l=-4096;
  176.       *up++ = _l2u[l];
  177.     }
  178. }
  179.